package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.player.HouseCreditInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class HouseCreditDaoImpl extends TempDao {

    public Map<Integer, HouseCreditInfo> getHouseCreditInfoMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, HouseCreditInfo> dataMap = new ConcurrentHashMap<>();
        String sql = "select * from t_p_house_credit";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                HouseCreditInfo data = new HouseCreditInfo();
                data.setId(rs.getInt("id"));
                data.setLevel(rs.getInt("level"));
                data.setCondition(rs.getInt("condition"));
                data.setSkillsList(rs.getString("skillsList"));
                data.setProduce(rs.getString("produce"));
                dataMap.put(data.getLevel(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
